<?php
declare(strict_types=1);
namespace Dao;
// hook dao_auth_nick_use.php

use Model\AuthNickModel;
use Swoole\Timer;

class AuthNickDao extends AuthNickModel
{
	// hook dao_auth_nick_public_start.php

	protected array $add_rule	=	[];
    protected array $edit_rule	=	[];

    protected array $rule	=	[
		/*
		"mobile"=>[
			"max"=>3
			"min"=>3
			"func"=>'isMobile'
			"error"=>false,
			'message'=>'格式有误'
		],
		"username"=>[
			"max"=>3
			"min"=>3
			"func"=>'checkS'
			"error"=>false,
			'message'=>'格式有误'
		],
		*/
	];
	//数据，字段，验证规则
	/*
	function isMobile($data,$field,$val){
	
		return true;
	}
	*/
	
	// hook dao_auth_nick_public_end.php
    public function auto_load()
    {
        // hook model_user_auto_load_start.php
        if ($this->http_server->worker_id == 0) {
            Timer::after(3000, function () {
                $this->reload();
            });
        }
    }

    public function reload($cond=[])
    {
        $data = $this->select($cond);
        if (!empty($data)) {
            foreach ($data as $row) {
                $this->T_AuthNick->set($row['NickName'],[
                    'NickID'=>$row['NickID'],
                    'ShopID'=>$row['ShopID'],
                    'Status'=>$row['Status'],
                    'ProductID'=>0,
                    'TimeOut'=>0,
                ]);
            }
        }
    }

	// hook dao_auth_nick_end.php
}
?>